package com.koron.css2.baseConfig.impl;

import com.koron.css2.ServerInterface;
import com.koron.css2.baseConfig.bean.BookBean;
import com.koron.css2.baseConfig.mapper.BookMapper;
import com.koron.css2.serviceManage.bean.RequestBean;
import com.koron.css2.serviceManage.bean.UserInfoBean;
import com.koron.css2.serviceManage.utils.CommonUtils;
import com.koron.util.Constant;
import com.koron.util.JsonUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.koron.ebs.mybatis.SessionFactory;
import org.swan.bean.MessageBean;
/**
 * 册本信息-修改
 * @author 许海宜
 */
public class BookUpdate implements ServerInterface {

	private static Logger logger = LogManager.getLogger(BookUpdate.class);

	@Override
	public MessageBean<?> exec(SessionFactory factory, UserInfoBean userInfo, RequestBean req) {
		try {
			BookMapper mapper = factory.getMapper(BookMapper.class);
			BookBean bean = JsonUtils.objectToPojo(req.getData(), BookBean.class);
			if(StringUtils.isBlank(bean.getId())){
				return MessageBean.create(Constant.MESSAGE_INT_FAIL, "主键不能为空。", void.class);
			}
			if(StringUtils.isBlank(bean.getBookNo())){
				return MessageBean.create(Constant.MESSAGE_INT_FAIL, "册本号不能为空。", void.class);
			}
			if(StringUtils.isBlank(bean.getBookName())){
				return MessageBean.create(Constant.MESSAGE_INT_FAIL, "册本名称不能为空。", void.class);
			}
			bean.setStatus("1");
			bean.setUpdateName(userInfo.getUserInfo().getName());
			bean.setUpdateAccount(userInfo.getUserInfo().getAcount());
			bean.setUpdateTime(CommonUtils.getCurrentTime());
			mapper.update(bean);
		} catch (Exception e) {
			logger.error("操作失败", e);
			return MessageBean.create(Constant.MESSAGE_INT_FAIL, "操作失败", void.class);
		}
		return MessageBean.create(Constant.MESSAGE_INT_SUCCESS, "success", void.class);
	}
}